import subprocess

def ping_host(ip_address):
    try:
        # 构造 ping 命令
        command = ["ping", "-n", "1", "-w", "1000", ip_address]  # Windows
        # command = ["ping", "-c", "1", "-W", "1", ip_address]  # Linux/Unix

        # 执行命令
        result = subprocess.run(
            command,
            capture_output=True,
            text=True,
            check=True
        )
        print(f"成功 ping 通 {ip_address}")
        print(result.stdout)
    except subprocess.CalledProcessError as e:
        print(f"无法 ping 通 {ip_address}")
        print(f"退出状态码: {e.returncode}")
        print(f"错误信息: {e.stderr}")
    except Exception as e:
        print(f"发生其他错误: {e}")

# 示例：ping 内网中的设备
ping_host("10.244.255.9")